/*
============================================================================
 Name        : MyPopMenu.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : Application view implementation
============================================================================
*/

// INCLUDE FILES
#include <BARSREAD.H>
#include <coemain.h>
#include <EIKENV.H>
#include <W32STD.H>
#include <TXTRICH.H>

#include <iTest_0xE0D9648A.rsg>

#include "MyDialog.h"
#include "MyDataCenter.h"
extern CMyDataCenter* iDataCenter;
// -----------------------------------------------------------------------------
// MyDialog::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
MyDialog* MyDialog::NewL( const TRect& aRect )
    {
    MyDialog* self = MyDialog::NewLC( aRect );
    CleanupStack::Pop( self );
    return self;
    }

// -----------------------------------------------------------------------------
// MyDialog::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
MyDialog* MyDialog::NewLC( const TRect& aRect )
    {
    MyDialog* self = new ( ELeave ) MyDialog();
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
    }

//
void MyDialog::ConstructL( const TRect& aRect )
{
/*	
    iClientRect = aRect;
    // Create a window for this application view
	ConstructSleepingDialogL( R_MODAL_DIALOG);
	CCoeControl* control = CreateCustomControlL(1000).iControl;
////	iTest = static_cast<MyTest*>(control);
*/
/*
	_LIT(KMyText, "The mobile");
	const TInt KMyId2 = 2; // Any arbitary value
	CCoeControl* control2 = CreateLineByTypeL(KNullDesC, KMyId2, EEikCtEdwin, NULL);
	iEdit1 = static_cast<CEikEdwin*>(control2);
	iEdit1->ConstructL( EEikEdwinNoHorizScrolling | EEikEdwinNoAutoSelection|EEikEdwinResizable, 20, 100, 10 );
	iEdit1->CreateTextViewL();
	iEdit1->SetTextL(&KMyText);
	iEdit1->SetExtent( TPoint( 0, 0 ), TSize(100,20));	
	*/
}

SEikControlInfo MyDialog::CreateCustomControlL(TInt aControlType) 
{ 
	if (aControlType == 1000) 
	{ 
		SEikControlInfo sinfo;
////		sinfo.iControl = MyTest::NewL(this);//new (ELeave)MyTest; 
		return sinfo;
	} 
	else
		return CEikDialog::CreateCustomControlL(aControlType);
}

// -----------------------------------------------------------------------------
// MyPopMenu::MyPopMenu()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//

MyDialog::MyDialog()
{
    // No implementation required

}


// -----------------------------------------------------------------------------
// MyPopMenu::~MyPopMenu()
// Destructor.
// -----------------------------------------------------------------------------
//
MyDialog::~MyDialog()
{
    // No implementation required
}

//用于预先调入对话框的网页，这样在执行excutewithoutloading前，可以修改
//其中的值
void MyDialog::PreloadPage(const TDesC& resname)
{
	;//iDataCenter->LoadMemPage(iTest->iRichText1, "dialog", resname);	
}

bool MyDialog::Execute(const TDesC& command)
{
	return true;
	TBuf<100> resname;
	resname.Copy(command);
	
//	iDataCenter->LoadMemPage(iTest->iRichText1, "dialog", _L("input1.xml"));	
	//iDataCenter->LoadMemPage(iTest->iRichText1, "dialog", resname);	


/////////////////////////////////////////////////
//	return ExecuteLD(R_MODAL_DIALOG);
//	RunLD();

	int res = RouseSleepingDialog();	
	return (res != 0);
}

bool MyDialog::InfoMsg(const TDesC& page, const TDesC& title, const TDesC& value)
{
	return true;
////	TBuf<100> resname;
////	resname.Copy(page);
////	
////	//iDataCenter->LoadMemPage(iTest->iRichText1, "dialog", resname);	
////    RichEditor()->ReplaceMyField(_L("title"), title, false);	
////    RichEditor()->ReplaceMyField(_L("value"), value, true);	    
////    
////	iTest->iRichText1->SetCursorPosL(0, EFalse);	
////
////	int res = RouseSleepingDialog();	
////	return (res != 0);
}

bool MyDialog::ExecuteWithoutLoad()
{
	int res = RouseSleepingDialog();	
	return (res != 0);
}
		
HBufC* MyDialog::GetPrompt()
{
	return NULL;	
//	HBufC* iUser = iTest->iRichText1->GetEditValue(_L("prompt"));
}

TKeyResponse MyDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
	// [[[ begin generated region: do not modify [Generated Contents]
	
	// ]]] end generated region [Generated Contents]
//	CEikonEnv::Static()->InfoMsg(_L("key event"));
	return CEikDialog::OfferKeyEventL( aKeyEvent, aType );
}	
	
void MyDialog::PreLayoutDynInitL()
{
//	iTest->ConstructL(this);		
}

void MyDialog::PostLayoutDynInitL()
{
	TRect rect = Rect();
////	iTest->SetRect(rect);
}

////void MyDialog::SizeChanged()
////{  
////	TRect rect = iClientRect;
////	iTest->SetExtent( TPoint( 1, 1 ), TSize( rect.Width(), rect.Height() ) );		
////}

MyRichEditor* MyDialog::RichEditor()
{
	return NULL;//iTest->iRichText1;
}
		
void MyDialog::SetSizeAndPosition(const TSize &  aSize)
{
	TRect rect = iClientRect; //TRect(0,0,100,100);
	TSize size = TSize( rect.Width(), rect.Height());	
	SetExtent( TPoint( 0, 0 ), size );	
	TRect tmp = CEikonEnv::Static()->ScreenDevice()->PixelsToTwips(TRect(size));

	TPoint pt(10,320-28-5-size.iHeight);
	SetPosition(pt);	
}

// End of File
